package com.woniuxy.project.campus.technical.utilTool;

import com.woniuxy.project.campus.AccountOpenFeign;
import com.woniuxy.project.campus.util.Result;
import com.woniuxy.project.campus.util.UtilJWP;
import io.jsonwebtoken.Claims;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class MyTool {
    //传入token 获得用户信息
    @Resource
    public AccountOpenFeign accountOpenFeign;
        public  Integer getUserIdByToken(String token) {
            Claims claims = UtilJWP.parseToken(token);
            return Integer.parseInt(claims.get("id").toString());
        }
        public  String getUserNameByToken(Integer userId) {
            Result userInfo = accountOpenFeign.getUserInfo(userId);
            Object data = userInfo.getData();
            System.out.println("********************************************"+data);
            return Result.success(data).getData().toString();
        }
}
